#!/usr/bin/python

import commands
import calendar
import time
import sys
import os
import re
import JoSql
import JoDef
import JoPrint

from optparse import OptionParser

import pdb

def nextid(username):
	sql = JoDef.NEXTID_SQL
	id = JoSql.sql_string(sql,username)
	return int(id)+1;

def add_task(username,id,options):
	if options.name:
		sql = JoDef.ADDTASK_SQL
		sql = re.sub("_TASKID_","%d"%id,sql)	
		sql = re.sub("_ENTRYTIME_","%d"%time.time(),sql)	
		sql = re.sub("_TASKNAME_",options.name,sql)
		if options.descr:
			sql = re.sub("_TASKDESC_",options.descr,sql)
		else:
			sql = re.sub("_TASKDESC_","",sql)
		print sql

def main():
	usage = "usage: %prog [options] command"
	parser = OptionParser(usage)
	parser.add_option("-u","--user",dest="username",help="journal user")
	
	(options,args) = parser.parse_args()
	if len(args) < 1: 
		parser.error("you must supply a command\n")
	if not options.username: 
		parser.error("you must supply a user with -u or --user\n")

	if args[0] == 'nextid':
		print nextid(options.username)

if __name__ == "__main__":
    main()
	
